
	<p>

	<form id="search_form" method="post" action="">
	<table cellspacing="2" cellpadding="0" border="0">
		<tr>
			<td><input type="text" id="search_query" name="search_query" value="" size="70" /></td>
			<td><input type="submit" id="btSearch" name="btSearch" value="Search" /></td>
			<td>&nbsp;</td>
			<td>Per page:</td>
			<td>
				<select id="ppg" name="ppg">
						<option value="10">10</option>
						<option value="15">20</option>
						<option value="50" selected>50</option>
						<option value="-1">all</option>
				</select>
			</td>
		</tr>
	</table>
	</form>
	
	<div id="search_results-container">
	
	
<table class="greentable">
    <thead>
    <tr>
		<th><a href="javascript:void(0);" onclick="setFilter('id', 'desc');">#</a></th>
		<th><a href="javascript:void(0);" onclick="setFilter('type', 'asc');">Type</a></th>
		<th><a href="javascript:void(0);" onclick="setFilter('firstname', 'asc');">Name</a></th>
		<th><a href="javascript:void(0);" onclick="setFilter('country', 'asc');">Country</a></th>
		<th><a href="javascript:void(0);" onclick="setFilter('email', 'asc');">E-mail</a></th>
		<th><a href="javascript:void(0);" onclick="setFilter('phone', 'asc');">Phone</a></th>
		<th><a href="javascript:void(0);" onclick="setFilter('mt4_uid', 'asc');">MT4 #</a></th>
		<th><a href="javascript:void(0);" onclick="setFilter('added', 'asc');">Registered</a></th>
		<th>&nbsp;</th>
    </tr>
    </thead>
    <tbody>
	<?php 
			foreach($users as $user){ 
	?>
    <tr>
        <td><a name="user-<?php echo $user->id; ?>"></a><?php echo $user->id; ?></td>
        <td><?php echo ucfirst(strtolower($user->type)); ?></td>
        <td><?php echo $user->firstname. ($user->firstname&&$user->lastname?' ':'') . $user->lastname?></td>
        <td><?php echo $user->country; ?></td>
        <td><?php echo $user->email; ?></td>
        <td><?php echo $user->phone; ?></td>
        <td><?php echo $user->mt4_uid; ?></td>
        <td><?php echo $user->added ? date("d/m/Y h:i:s A T",$user->added) : 'N/A'; ?></td>
		<td class="actions">
			<a class="view" title="Add to E-mail recepients" href="javascript:void(0);" onclick="parent.userSelected('<?=$user->id?>|<?php echo $user->mt4_uid; ?>|<?php echo addslashes($user->firstname); ?>|<?php echo addslashes($user->lastname); ?>');">add</a> 
		</td>
	</tr>
    <?php } ?>
	<?php
			if($users->result_count()==0)
			{
	?>
	<tr><td colspan="9">No users found.</td></tr>
	<?php
			}
			else
			{
	?>
	<tr>
		<td colspan="9"><?=$paging?></td>
	</tr>
	<?php
			}
	?>
    </tbody>
</table>

	</div>
	
	<div id="dialog" title=""></div>
	
	<script language="javascript">

		var search_query = '';
		var per_page	 = 50;
		var sort_by		 = 'id';
		var sort_order 	 = 'asc';
		var search_token = '';
		
		jQuery(document).ready(function(){
				jQuery('#search_form').bind('submit', function(){
					var sq = Cleanfield(jQuery('#search_query').val());
					if(sq!='' && sq.length<3)
					{
							alert('3 characters minimum required!');
							jQuery('#search_query').focus();
					}
					else
					{
						search_query = jQuery('#search_query').val();
						jxLoadUsers('1', true);
						return(false);
					}
				});
				
				jQuery('#ppg').bind('change', function(){
						per_page = jQuery(this).val();
				});
				
				// live search
				jQuery('#search_query').bind('keyup', function(){
						var q = jQuery.trim(jQuery(this).val());
						if(q.length>2) jxLoadUsers('1', false);
				});
				
				
		});
		
		function setFilter(sb, so) {
				sort_by 	= sb;
				sort_order 	= so;
				jxLoadUsers('1', true);
		}

		function jxLoadUsers(page, s) {
		
			if(s) jQuery.blockUI({ message: '<h3><img src="'+__base_url+'images/busy.gif" /> Loading...</h3>' });
		
			var postdata = "";
			search_query = jQuery('#search_query').val();
			postdata = postdata 	+ "page=" 			+ Cleanfield(page);
			postdata = postdata 	+ "&search_query=" 	+ Cleanfield(search_query);
			postdata = postdata 	+ "&per_page=" 		+ Cleanfield(per_page);
			postdata = postdata 	+ "&sort_by=" 		+ Cleanfield(sort_by);
			postdata = postdata 	+ "&sort_order=" 	+ Cleanfield(sort_order);
			postdata = postdata 	+ "&__csrf=" 		+ __csrf;
			postdata = postdata 	+ "&__ts=" 			+ __ts;
			
			jQuery.ajax({
					type: 'POST',
					url: __base_url+'admin/jx_load_select_users',
					data: postdata,
					cache:false,
					success: function(msg){
							// alert(msg);
							if(s) jQuery.unblockUI();
							
							try {
								var _obj = jQuery.parseJSON(msg);
								// alert(_obj.stat);
								if(typeof _obj.stat != 'undefined' && _obj.stat=='success' && typeof _obj.data != 'undefined')
								{
									jQuery('#search_results-container').html(_obj.data);
								}
							} catch(err) {
								// alert(msg);
							}
					},
					error: function(xhr,ajaxOptions,thrownError){
							alert(xhr.responseText);
					}
			});
		}
		
		function Cleanfield(value){			
			var value = encodeURIComponent(jQuery.trim(value));
			return value;
		}
		
</script>
	
	